package com.yangyang.lamviarm.util;

import java.util.List;

public enum TypeEnum {

	DEFAULT, OBJECT, POINT, ROBOT;

	public static TypeEnum parseType(String str) {
		TypeEnum type = DEFAULT;
		if (str.equals("OBJECT"))
			type = OBJECT;
		else if (str.equals("POINT"))
			type = POINT;
		else if (str.equals("ROBOT"))
			type = ROBOT;
		else {
			System.err.println("wrong type: " + str);
			assert (false);
		}
		return type;
	}

	public static boolean exactFit(List<TypeEnum> paramType, TypeEnum[] preType) {
		if (paramType.size() != preType.length)
			return false;
		boolean[] flag = new boolean[paramType.size()];
		for (int i = 0; i < flag.length; i++)
			flag[i] = false;

		for (int i = 0; i < preType.length; i++) {
			if (!flag[i]
					&& (paramType.get(i) == preType[i] || paramType.get(i) == ROBOT
							&& preType[i] == OBJECT))
				flag[i] = true;
			else
				break;

		}
		boolean result = true;
		for (int i = 0; i < flag.length; i++) {
			result &= flag[i];
			if (!result)
				break;
		}

		return result;
	}

	public static boolean fit(List<TypeEnum> types, TypeEnum[] fitableTypes) {
		boolean result = true;
		for (TypeEnum t : fitableTypes) {
			if ((!types.contains(t) && t != TypeEnum.OBJECT)
					|| (t == OBJECT && !types.contains(t) && !types
							.contains(ROBOT))) {
				result = false;
				break;
			}
		}
		return result;
	}
}
